SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




ALTER  trigger [tb_comexpproportionfinished_ai] on dbo.tb_comexpproportionfinished for insert
as
begin
  set nocount on
  declare @nbid int,
          @nrelationbid int,
          @nrelationbno int,
          @nbstate int, 
          @namount decimal(18,2)

  declare tb_comexpproportionfinished_cur cursor forward_only optimistic for
  select bid,relationbid,relationbno,amount from inserted
  open tb_comexpproportionfinished_cur
  fetch next from tb_comexpproportionfinished_cur into 
  @nbid,@nrelationbid,@nrelationbno,@namount
  while( @@fetch_status = 0 )
  begin
    update tb_comcheckacceptdtl set relationcount = relationcount+1 , expense = expense + @namount  
    where bid = @nrelationbid and bno = @nrelationbno

    fetch next from tb_comexpproportionfinished_cur into 
    @nbid,@nrelationbid,@nrelationbno,@namount
  end
  close tb_comexpproportionfinished_cur
  deallocate tb_comexpproportionfinished_cur
end





GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

